# -*- coding: utf-8 -*-
from django.conf import settings
from django.db.models import CharField, IntegerField


class CountryField(CharField):
    def __init__(self, *args, **kwargs):
        from miles.db.choices import COUNTRIES
        kwargs.setdefault('max_length', 2)
        kwargs.setdefault('choices', COUNTRIES)
        super(CharField, self).__init__(*args, **kwargs)

    def get_internal_type(self):
        return 'CharField'


class MonthField(IntegerField):
    def __init__(self, *args, **kwargs):
        from miles.db.choices import MONTHS
        kwargs.setdefault('choices', MONTHS)
        super(IntegerField, self).__init__(*args, **kwargs)

    def get_internal_type(self):
        return 'IntegerField'


# South 0.7+ support
if 'south' in settings.INSTALLED_APPS:
    try:
        from south.modelsinspector import add_introspection_rules
    except ImportError:
        pass # South < 0.7
    else:
        add_introspection_rules([], ["^miles\.db\.fields\.CountryField"])
        add_introspection_rules([], ["^miles\.db\.fields\.MonthField"])
